const { DataTypes, Model } = require('sequelize');

const sequelize = require('../db/seq.js');

const Goods = require('../model/goods.model')

const Cart = sequelize.define('learn_carts', {
    goods_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: "商品的id",
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        comment: "用户的id",
    },
    number: {
        type: DataTypes.INTEGER,
        allowNull: false,
        defaultValue: 1,
        comment: "商品的数量",
    },
    selected: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: "是否选择的状态",
    },
})

// Cart.sync({ force: true })
Cart.belongsTo(Goods, {
    foreignKey: "goods_id",
    as: "good_info"
})
module.exports = Cart